package WeekThree;

import java.util.Arrays;
import java.util.Scanner;

public class Sort {
    public static void main(String[] args) {
        int[]arry = new int[7];
        int len=7;
        Sort.input(arry,len);
        System.out.print("排序前");
        Sort.output(arry,len);
        quickSort(arry,0, arry.length-1);
        System.out.print("排序后");
        Sort.output(arry,len);

    }
    public static void input(int[] arry,int len) {
        System.out.println("请给数组输入连续的"+len+"数据");
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < len; i++) {
            arry[i]=scanner.nextInt();
        }
    }
    public static void output(int[]arry,int len) {
        for (int i = 0; i < len; i++) {
            System.out.print(" " + arry[i]);
        }
        System.out.println();
    }
    public static void quickSort(int[] arry,int left,int right){
            if(left>right){
                return;
            }
            int base = arry[left];
            int i = left;
            int j = right;
            while(i!=j){
                while(arry[j]>=base && i<j){
                    j--;
                }
                while(arry[i]<=base && i<j){
                    i++;
                }
                int tem = arry[i];
                arry[i] = arry[j];
                arry[j] = tem;
            }
            arry[left] = arry[i];
            arry[i] = base;
            quickSort(arry,left,i-1);
            quickSort(arry,j+1,right);

    }
}
